#include "comm.hpp"

int main()
{
    key_t key = getKey();
    printf("key = 0x%x\n", key);
    int shmid = getShm(key);
    printf("shmid = %d\n", shmid);
    char *start = (char *)attachShm(shmid);
    printf("attach success, address start: %p\n", start);
    sleep(2);

    const char *msg = "hello server, 我是另一个进程，我正在与你通信。";
    pid_t pid = getpid();
    int cnt = 1;
    while (true)
    {
        snprintf(start, MAX_SIZE, "%s[pid:%d][消息编号:%d]", msg, pid, cnt++);
        sleep(1);
        if (cnt == 5)
        {
            break;
        }
    }
    detachShm(start);
    return 0;
}